package org.td.engine.entity;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import org.td.Application;

public class HealthBar {

    private Sprite indicator;
    private Sprite background;
    private int size;
    private int height = 5;

    public HealthBar(int size) {
        this.size = size;
        indicator = new Sprite(Application.findAsset("healthbar"));
        background = new Sprite(Application.findAsset("healthbar_background"));
        background.setSize(size, height);
        indicator.setSize(0, 0);

    }

    public void update(float x, float y, float percentage) {
        if (percentage >= 0.75f){
            indicator.setColor(Color.GREEN);
        } else if (percentage >= 0.5f) {
            indicator.setColor(Color.YELLOW);
        } else {
            indicator.setColor(Color.RED);
        }
        indicator.setSize(percentage * size, height);
        indicator.setPosition(x - size / 2f, y);
        background.setPosition(x - size / 2f, y);
    }

    public void render(SpriteBatch batch) {
        background.draw(batch);
        indicator.draw(batch);
    }
}
